<?php

class Msamecontent extends TV_Model {

    function MUser() {
        parent::TV_Model();
        //Sample connect another db: parent::QS_Model("oldhouseweb");        
    }
    
    public function getItemEachTable($table, $start, $off, $status){
        $sql = "SELECT id, title, sumary, url_image, created_date
                FROM {$table}
                WHERE status = ?
                ORDER BY id DESC
                LIMIT {$start}, {$off}
                ";
        return $this->query_array($sql, array($status));
    }

    public function getAllItemOfCategory($table, $status) {
        $sql = "SELECT id, title, url_image, sumary, type, created_date
                FROM {$table}
                WHERE status = ?
                ";
        return $this->query_array($sql, array($status));
    }

    public function getAllItemOfCategoryLimit($table, $start, $off, $status) {
        $sql = "SELECT id, title, url_image, sumary, type, created_date
                FROM {$table}
                WHERE status = ?
                ORDER BY id DESC
                LIMIT {$start}, {$off}
                
                ";
        return $this->query_array($sql, array($status));
    }

    public function getAllItemByType($table, $type, $status) {
        $sql = "SELECT id, title, url_image, sumary, type, created_date
                FROM {$table}
                WHERE type = ?
                AND status = ?
                ";
        return $this->query_array($sql, array($type, $status));
    }

    public function getAllItemByTypeLimit($table, $type, $start, $off, $status) {
        $sql = "SELECT id, title, url_image, sumary, type, created_date
                FROM {$table}
                WHERE type = ?
                AND status = ?
                                ORDER BY id DESC
                LIMIT {$start}, {$off}
                ";
        return $this->query_array($sql, array($type, $status));
    }

    public function infoItemById($table_db, $id) {
        $sql = "SELECT title, content
                FROM {$table_db}
                WHERE id = ?";
        return $this->query_row($sql, array($id));
    }

    public function infoItemOtherSameItemCurrent($table_db, $id, $start, $off, $status) {
        $sql = "SELECT id, title, content, type, created_date
                FROM {$table_db}
                WHERE id != ?
                AND status = ?
                ORDER BY RAND()
                LIMIT {$start}, {$off}";
        return $this->query_array($sql, array($id, $status));
    }

}